(function () {
    $.fn.extend({
        carousel_auto() {
            class Swiper {
                constructor(el) {
                    this.el = el;
                    this.oLis1 = this.el.children().eq(0).children();
                    this.oLis2 = this.el.children().eq(3).children();
                    this.imgIndex = 0;
                    this.toPlay();
                    this.clickHandler()
                }
                toPlay() {
                    clearInterval(this.timer);
                    this.timer = setInterval(() => {
                        this.imgIndex++
                        if (this.imgIndex > 1) {
                            this.imgIndex = 0;
                        }
                        this.autoPlay();
                    }, 3000)
                }
                autoPlay() {
                    this.oLis1.eq(this.imgIndex).stop().animate({ opacity: 1 }, 500).siblings().stop().animate({ opacity: 0 }, 500);
                    this.oLis2.eq(this.imgIndex).addClass("nav-txt").siblings().removeClass("nav-txt");
                }
                clickHandler() {
                    this.oLis2.each((index, item) => {
                        item.onclick = () => {
                            this.imgIndex = index;
                            this.autoPlay();
                            this.toPlay();
                        }
                    })
                }
            }

            new Swiper(this);
        },
        two_menu() {
            class Swiper2 {
                constructor(el) {
                    this.el = el;
                    this.oLis = this.el.children().eq(0).children().eq(0).children().eq(0);
                    this.oUl = this.el.children().eq(1).children().eq(0);
                    this.oLis2 = this.el.children().eq(1).children().eq(0).children();
                    this.oBox = this.el.children().eq(1).children().eq(1).children();
                    this.oList = this.el.children().eq(1);
                    this.mouseHandler();
                }
                mouseHandler() {
                    this.oLis.on("mouseenter", () => {
                        this.oList.stop().slideDown();
                    }).mouseleave(()=>{
                        this.oList.stop().slideUp();

                    })
                    this.oLis2.each((index, item) => {
                        item.onmouseenter = () => {
                            this.oBox.eq(index).show().siblings().hide();
                        }
                    })
                    this.oList.on("mouseleave", () => {
                        this.oBox.hide();
                        this.oList.stop().slideUp();
                    })
                }
            }
            new Swiper2(this);
        }
    })
})()

$(function () {
    $("#index-nav").carousel_auto();
    $(".top-head-nav").two_menu();
})